{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "1d0df6a8",
   "metadata": {},
   "outputs": [],
   "source": [
    "from PyPDF2 import PdfFileReader,PdfFileMerger\n",
    "\n",
    "#要合并的多个pdf文件\n",
    "\n",
    "pdf_files = (\"./pandas数据分析100题/1-3数据结构DataFrame.pdf\",\n",
    "             \"./pandas数据分析100题/4股票数据集.pdf\",\n",
    "             \"./pandas数据分析100题/5电信客户流失数据集.pdf\",\n",
    "             \"./pandas数据分析100题/6两列随机数据集.pdf\",\n",
    "             \"./pandas数据分析100题/7随机矩阵数据集.pdf\",\n",
    "             \"./pandas数据分析100题/8⼆⼿⻋数据集⼀.pdf\",\n",
    "             \"./pandas数据分析100题/9⼆⼿⻋数据集⼆.pdf\",\n",
    "             \"./pandas数据分析100题/10伦敦数据集⼀.pdf\",\n",
    "             \"./pandas数据分析100题/11伦敦数据集二.pdf\",\n",
    "             \"./pandas数据分析100题/12-13保险数据集一.pdf\",\n",
    "             \"./pandas数据分析100题/14衣服购买数据集.pdf\",\n",
    "             \"./pandas数据分析100题/15JSON数据文件分析.pdf\")\n",
    "\n",
    "result_pdf = PdfFileMerger()\n",
    "\n",
    "#依次读取每个pdf内容，并进行合并\n",
    "\n",
    "for pdf in pdf_files:\n",
    "    with open(pdf,\"rb\")as fp:\n",
    "        pdf_reader = PdfFileReader(fp)\n",
    "        if pdf_reader.isEncrypted:\n",
    "            print(f'忽略加密文件: {pdf}')\n",
    "            continue\n",
    "        result_pdf.append(pdf_reader,import_bookmarks=True)\n",
    "        \n",
    "#保存合并pdf文件\n",
    "\n",
    "result_pdf.write(\"./pandas数据分析100题/合并.pdf\")\n",
    "result_pdf.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "af018ba5",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "3ee59faf",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "8225b5db",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "8798853c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
